package YahooFinance.helper.updatethread;

import YahooFinance.MarketDataBean;
import YahooFinance.MarketDataBeanRepository;
import YahooFinance.YahooQuoteFetcher;
import android.app.Activity;
import android.widget.TextView;

public class AndroidUpdateThread extends UpdateThread {

	private  Activity mActivity;
	private TextView[] mTextViews;
	
	public AndroidUpdateThread(int pSeconds, YahooQuoteFetcher pFetcher,
			Activity pActivity, TextView... pTextView) {
		super(pSeconds, pFetcher, null);
		
		mActivity = pActivity;
		mTextViews = pTextView;
	}

	@Override
	public void doOnUpdate() {
		mActivity.runOnUiThread(updateTextViewRunnable);

	}
	
	Runnable updateTextViewRunnable = new Runnable() {
		
		@Override
		public void run() {
			MarketDataBean lReturnBean = MarketDataBeanRepository.getInstance().getLatestBeanData("Symbol chooseing not yet implemented");
			
			if (mTextViews.length >= 1){
				mTextViews[0].setText(lReturnBean.getSymbol());
			}
			if (mTextViews.length >= 2){
				mTextViews[1].setText(lReturnBean.getPriceAsString());
			}
			if (mTextViews.length >= 3){
				mTextViews[2].setText(lReturnBean.getTimeAsString());
			}
			if (mTextViews.length >= 4){
				mTextViews[3].setText(lReturnBean.getDateAsString());
			}
		}
	};

}